using Ardalis.Specification;
using SharedKernel;

namespace Domain.Todos.Specifications;

/// <summary>
/// 逾期待办事项规约
/// </summary>
public sealed class OverdueTodosSpecification : Specification<TodoItem>
{
    public OverdueTodosSpecification(Guid userId, IDateTimeProvider dateTimeProvider)
    {
        DateTime now = dateTimeProvider.UtcNow;
        
        Query.Where(todo => todo.UserId == userId && 
                           !todo.IsCompleted && 
                           todo.DueDate.HasValue && 
                           todo.DueDate.Value < now)
             .OrderBy(todo => todo.DueDate)
             .ThenByDescending(todo => todo.Priority);
    }
}
